import Qt 4.7
import QtMobility.sensors 1.1

Rectangle {
    id: root
    width: parent.width
    height: parent.height
    opacity: 1
    color: "black"

    Compass {
        id: comp
        //active: true
        //onReadingChanged: console.log("Compass reading changed: " + reading.azimuth)
    }

    OrientationSensor {
        id: orientation
        active: true

        onReadingChanged: {
            if (reading.orientation == OrientationReading.TopUp)
                content.state = "TopUp";
            else if (reading.orientation == OrientationReading.TopDown)
                content.state = "TopDown";
            else if (reading.orientation == OrientationReading.LeftUp)
                content.state = "LeftUp";
            else if (reading.orientation == OrientationReading.RightUp)
                content.state = "RightUp";
            else if (reading.orientation == OrientationReading.FaceUp)
                content.state = "FaceUp";
            else if (reading.orientation == OrientationReading.FaceDown)
                content.state = "FaceDown";
            else
                content.state = "";
        }
    }

    Item {
        id: content
        anchors.centerIn: parent
        Text {
            id: text
            text: "Orientation: Unknown"
            color: "white"
            font.pointSize: 24
            anchors.centerIn: parent
        }

        states: [
            State {
                name: "TopUp"
                changes: [
                    PropertyChanges { target: text; text: "Orientation: TopUp" }
                ]
            },
            State {
                name: "TopDown"
                changes: [
                    PropertyChanges { target: content; rotation: 180 },
                    PropertyChanges { target: text; text: "Orientation: TopDown" }
                ]
            },
            State {
                name: "LeftUp"
                changes: [
                    PropertyChanges { target: content; rotation: -90 },
                    PropertyChanges { target: text; text: "Orientation: LeftUp" }
                ]
            },
            State {
                name: "RightUp"
                changes: [
                    PropertyChanges { target: content; rotation: 90 },
                    PropertyChanges { target: text; text: "Orientation: RightUp" }
                ]
            },
            State {
                name: "FaceUp"
                changes: [
                    PropertyChanges { target: text; text: "Orientation: FaceUp" }
                ]
            },
            State {
                name: "FaceDown"
                changes: [
                    PropertyChanges { target: text; text: "Orientation: FaceDown" }
                ]
            }
        ]

        transitions: Transition {
            NumberAnimation { properties: "rotation"; easing.type: Easing.OutBounce; duration: 400 }
        }
    }
}

